package com.itfreer.bpm.config.entity;
import java.io.Serializable;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.springframework.beans.BeanUtils;

import com.itfreer.bpm.config.entity.BpmConfigEntity;
import com.itfreer.bpm.config.entity.BpmTaskConfigEntity;
import com.itfreer.form.api.JdbcBaseEntity;


/**
 * 流程配置信息表
 */
@Entity(name = "bpm_config")
@Table(indexes = { @Index(name = "act_bpm_defname", columnList = "act_defname"),
		@Index(name="act_bpm_defid", columnList="act_defid")})
public class JdbcBpmConfigEntity implements JdbcBaseEntity<BpmConfigEntity>, Serializable { 
	private static final long serialVersionUID = 4673423560339517162L;
	
	/**
	 * 元数据信息ID
	 * 主键
	 */
	@Id
	@Column(name = "act_id", length = 50, nullable = false)
	private String actid;
	
	@Column(name = "act_group")
	private String actgroup;
	
	@Column(name = "act_defid")
	private String actdefid;
	
	@Column(name = "act_defname")
	private String actdefname;
	
	@Column(name = "act_publish")
	private String actpublish;
	
	@Column(name = "prj_url")
	private String prjurl;
	
	@Column(name = "prj_namfld")
	private String prjnamfld;
	
	@Column(name = "prj_forname")
	private String prjforname;
	
	@Column(name = "prj_vi")
	private String prjvi;
	
	@Column(name = "tl_total")
	private Double tltotal;
	
	@Column(name = "tl_statask")
	private String tlstatask;
	
	@Column(name = "tl_endtask")
	private String tlendtask;
	
	/**
	 * 流程节点配置
	 */
	@SuppressWarnings("deprecation")
	@org.hibernate.annotations.ForeignKey(name = "none")
	@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
	@JoinColumn(name = "act_id")
	@OrderBy("task_order ASC")
	private Set<JdbcBpmTaskConfigEntity> taskconfigs = new LinkedHashSet<JdbcBpmTaskConfigEntity>();

	/**
	 * 流程节点配置
	 * @return
	 */
	public Set<JdbcBpmTaskConfigEntity> getTaskconfigs() {
		return taskconfigs;
	}
	/**
	 * 流程节点配置
	 * @return
	 */
	public void setTaskconfigs(Set<JdbcBpmTaskConfigEntity> taskconfigs) {
		this.taskconfigs = taskconfigs;
	}
	/**
	 * 数据库主键
	 * @return
	 */
	public  String getActid() {
		return actid;
	}
	/**
	 * 数据库主键
	 * @return
	 */
	public  void setActid(String actid) {
		this.actid = actid;
	}

	/**
	 * 分组信息
	 * @return
	 */
	public  String getActgroup() {
		return actgroup;
	}

	/**
	 * 分组信息
	 * @param actgroup
	 */
	public  void setActgroup(String actgroup) {
		this.actgroup = actgroup;
	}

	/**
	 * 流程定义id
	 * @return
	 */
	public  String getActdefid() {
		return actdefid;
	}

	/**
	 * 流程定义id
	 * @param 
	 */
	public  void setActdefid(String actdefid) {
		this.actdefid = actdefid;
	}
	
	/**
	 * 流程名称
	 * @param 
	 */
	public  String getActdefname() {
		return actdefname;
	}

	/**
	 * 流程名称
	 * @param 
	 */
	public  void setActdefname(String actdefname) {
		this.actdefname = actdefname;
	}

	/**
	 * 流程发布状态
	 * @param 
	 */
	public  String getActpublish() {
		return actpublish;
	}

	/**
	 * 流程发布状态
	 * @param 
	 */
	public  void setActpublish(String actpublish) {
		this.actpublish = actpublish;
	}

	/**
	 * 项目访问地址
	 * @param 
	 */
	public  String getPrjurl() {
		return prjurl;
	}

	/**
	 * 项目访问地址
	 * @param 
	 */
	public  void setPrjurl(String prjurl) {
		this.prjurl = prjurl;
	}

	/**
	 * 提取项目展示名称中字段
	 * @param 
	 */
	public  String getPrjnamfld() {
		return prjnamfld;
	}

	/**
	 * 提取项目展示名称中字段
	 * @param 
	 */
	public  void setPrjnamfld(String prjnamfld) {
		this.prjnamfld = prjnamfld;
	}

	/**
	 * 表单名称
	 * @param 
	 */
	public  String getPrjforname() {
		return prjforname;
	}

	/**
	 * 表单名称
	 * @param 
	 */
	public  void setPrjforname(String prjforname) {
		this.prjforname = prjforname;
	}

	/**
	 * 表单viewid
	 * @param 
	 */
	public  String getPrjvi() {
		return this.prjvi;
	}

	/**
	 * 表单viewid
	 * @param 
	 */
	public  void setPrjvi(String prjvi) {
		this.prjvi = prjvi;
	}

	/**
	 * 流程限时
	 * @param 
	 */
	public  Double getTltotal() {
		return tltotal;
	}

	/**
	 * 流程限时
	 * @param 
	 */
	public  void setTltotal(Double tltotal) {
		this.tltotal = tltotal;
	}

	/**
	 * 开始计时环节
	 * @param 
	 */
	public  String getTlstatask() {
		return tlstatask;
	}

	/**
	 * 开始计时环节
	 * @param 
	 */
	public  void setTlstatask(String tlstatask) {
		this.tlstatask = tlstatask;
	}

	/**
	 * 结束计时环节
	 * @param 
	 */
	public  String getTlendtask() {
		return tlendtask;
	}

	/**
	 * 结束计时环节
	 * @param 
	 */
	public  void setTlendtask(String tlendtask) {
		this.tlendtask = tlendtask;
	}
	@Override
	public void from(BpmConfigEntity t) {
		BeanUtils.copyProperties(t, this);
		
		//栽培技术表-start-
		Set<JdbcBpmTaskConfigEntity> jdbctaskconfigs = new LinkedHashSet<JdbcBpmTaskConfigEntity>();
		Set<BpmTaskConfigEntity> taskconfigs = t.getTaskconfigs();
		if (taskconfigs != null) {
			for (BpmTaskConfigEntity item : taskconfigs) {
				JdbcBpmTaskConfigEntity jItem = new JdbcBpmTaskConfigEntity();
				jItem.from(item);
				jdbctaskconfigs.add(jItem);
			}
		}
		this.setTaskconfigs(jdbctaskconfigs);
	}
	@Override
	public void setId(String arg0) {
		// TODO Auto-generated method stub
		this.actid = arg0;
	}
	@Override
	public BpmConfigEntity toEntity() {
		BpmConfigEntity toEntity = new BpmConfigEntity();
		BeanUtils.copyProperties(this, toEntity);
		
		//查询匹配条件-start-
		Set<BpmTaskConfigEntity> taskconfigs = new LinkedHashSet<BpmTaskConfigEntity>();
		Set<JdbcBpmTaskConfigEntity> jdbctaskconfigs = this.getTaskconfigs();
		
		if (jdbctaskconfigs != null) {
			for (JdbcBpmTaskConfigEntity item : jdbctaskconfigs) {
				taskconfigs.add(item.toEntity());
			}
		}
		toEntity.setTaskconfigs(taskconfigs);
		return toEntity;
	}
}
